package com.sjyl.kaoshitong.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.orhanobut.logger.Logger;
import com.sjyl.kaoshitong.fragment.MyDocumentFolderFragment;
import com.sjyl.kaoshitong.fragment.MyDocumentFragment;
import com.sjyl.kaoshitong.fragment.QACenterFragment;
import com.sjyl.kaoshitong.fragment.QARewardFragment;
import com.sjyl.kaoshitong.util.Utility;

/**
 * Created by ChangerLow on 15/4/2.
 * Email: changerlow@qq.com
 */
public class SlidingFragmentAdapter extends FragmentPagerAdapter {
    private static final String TAG="SlidingFragmentAdapter";
    private String[] titles = null;
    private Utility.TAB_TYPE type;

    public SlidingFragmentAdapter(FragmentManager fm, String[] titles, Utility.TAB_TYPE tabType) {
        super(fm);
        this.titles = titles;
        this.type = tabType;
    }

    @Override
    public Fragment getItem(int position) {
        String title = titles[position];
        Fragment fragment = null;
        Logger.d(TAG, "Sliding Fragment adapter get item "+ title);
        switch (type) {
            case DOCUMENT:
                switch (position) {
                    case 0:
                        fragment = MyDocumentFolderFragment.newInstance(title);
                        break;
                    case 1:
                        fragment = MyDocumentFragment.newInstance(title);
                        break;
                    case 2:
                        fragment = MyDocumentFragment.newInstance(title);
                        break;
                    default:
                        break;
                }
                break;
            case QA:
                switch (position){
                    case 0:
                        fragment = QARewardFragment.newInstance(position);
                        break;
                    case 1:
                        fragment = QARewardFragment.newInstance(position);
                        break;
                    case 2:
                        fragment = QARewardFragment.newInstance(position);
                        break;
                    case 3:
                        fragment = QACenterFragment.newInstance(title);
                        break;
                    default:
                        break;
                }
                break;
            case QB:
                switch (position){
                    case 0:
                        fragment = MyDocumentFragment.newInstance(title);
                        break;
                    case 1:
                        fragment = QACenterFragment.newInstance(title);
                        break;
                    default:
                        break;
                }

                break;
            default: fragment =  MyDocumentFragment.newInstance(title);
        }
        return fragment;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    @Override
    public int getCount() {
        return titles.length;
    }
}
